package com.atguigu.guli.service.base.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/** 自动添加的处理器
 * @author Jia Fa
 * @create 2021-10-26 19:13
 */
@Component
public class GlobalMetaObjectHandler implements MetaObjectHandler {
    /**
     * 添加时间自动注入  与JavaBean内的@TableField注解搭配
     * @param metaObject
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        metaObject.setValue("gmtCreate", new Date());
        this.updateFill(metaObject);
    }

    //更新自动注入修改时间
    @Override
    public void updateFill(MetaObject metaObject) {
        metaObject.setValue("gmtModified", new Date());
    }
}
